package com.example.mapper;

import com.example.pojo.Emp;
import com.example.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

//员工信息
@Mapper
public interface EmpMapper {

    //查询员工记录总数
//    @Select("select count(*) from emp e left join dept d on e.dept_id = d.id")
//    public long count();
//
      //分页查询员工
//    @Select("select e.*, d.name deptName from emp e left join dept d on e.dept_id = d.id order by e.update_time desc limit #{start},#{pagoSize} ")
//    public List<Emp> list(Integer start,Integer pagoSize);
//原始的分页查询实现

//    @Select("select e.*, d.name deptName from emp e left join dept d on e.dept_id = d.id order by e.update_time desc")
//    public List<Emp> list(String name, Integer gender, LocalDate begin, LocalDate end)

//     条件查询员工信息
      public List<Emp> list(EmpQueryParam empQueryParam);

      //保存员工
      @Options(useGeneratedKeys = true,keyProperty = "id")//获取生成的主键值
      @Insert("insert into emp(username,password,name,gender,phone,job,salary,entry_date,dept_id,create_time,update_time) " +
              "values(#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary},#{entryDate},#{deptId},#{createTime},#{updateTime})")
      public void insert(Emp emp);

      //批量删除员工
      void deleteByIds(List<Integer> ids);

      // 根据id查询员工信息
      Emp getInfo(Integer id);

      //根据id更新员工信息
      void updateBYID(Emp emp);

      //统计员工职位人数
      @MapKey("pos")
      List<Map<String,Object>>countEmoJobData();

      //统计员工性别人数
      @MapKey("name")
    List<Map<String, Object>> countEmoGenderData();

      //根据用户名和密码查询员工
      @Select("select * from emp where username = #{username} and password = #{password}")
      Emp selectByUsername(Emp emp);
}

